home *** CD-ROM | disk | FTP | other *** search
- // FormulaDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "VCDemo.h"
- #include "FormulaDlg.h"
-
- #include <afxpriv.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CFormulaDlg dialog
-
-
- CFormulaDlg::CFormulaDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFormulaDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFormulaDlg)
- m_exprstr = _T("A3+B3+C3");
- m_result = _T("");
- //}}AFX_DATA_INIT
- }
-
-
- void CFormulaDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFormulaDlg)
- DDX_Control(pDX, IDC_SGCTRL1, m_ctrl);
- DDX_Text(pDX, IDC_EDIT_EXPR, m_exprstr);
- DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CFormulaDlg, CDialog)
- //{{AFX_MSG_MAP(CFormulaDlg)
- ON_BN_CLICKED(IDC_BUTTON_CALC, OnButtonCalc)
- ON_BN_CLICKED(IDC_BUTTON_EXPRHELP, OnButtonExprhelp)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CFormulaDlg message handlers
-
- BOOL CFormulaDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_ctrl.DoSetCellString( 0,1, "January" );
- m_ctrl.DoSetCellString( 1,1, "February" );
- m_ctrl.DoSetCellString( 2,1, "March" );
- m_ctrl.DoSetCellString( 3,1, "first quarter" );
- m_ctrl.DoSetCellString( 4,1, "total year" );
-
- m_ctrl.DoSetCellValue( 0,2, 567.5 );
- m_ctrl.DoSetCellValue( 1,2, 679.3 );
- m_ctrl.DoSetCellValue( 2,2, 368.3 );
-
- m_ctrl.DoSetFormula( 3,2, "a3+b3+c3" );
- m_ctrl.DoSetFormula( 4,2, "d3*4" );
-
- m_ctrl.SetPageLabelVisible( FALSE );
- COleVariant var( "VCDEMO" );
- m_ctrl.DoSetMessageTitle( var );
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CFormulaDlg::OnButtonCalc()
- {
- // TODO: Add your control notification handler code here
- USES_CONVERSION; //add #include <afxpriv.h> in your stdafx.h
-
- UpdateData();
- if( !m_exprstr.IsEmpty() ){
- short type;
- char buf[40];
- COleVariant var;
- if( m_ctrl.DoCalculateExpr( m_exprstr, &type, &var ) ){
- if( type == 0 ){
- sprintf( buf, "%G", var.dblVal );
- m_result = CString( "value: ")+buf;
- }
- else if( type == 1 ){
- m_result = CString( "string: ")+W2A(V_BSTR(&var));;
- }
- else if( type == 2 ){
- m_result = CString( "cell: ")+W2A(V_BSTR(&var));;
- }
- else if( type == 3 ){
- m_result = CString( "area: ")+W2A(V_BSTR(&var));;
- }
- UpdateData( FALSE );
- }
- else{
- AfxMessageBox( "Syntax!" );
- }
- }
- }
-
- void CFormulaDlg::OnButtonExprhelp()
- {
- // TODO: Add your control notification handler code here
- AfxMessageBox( " CELL support 4 data types: double value, string, cell, area. " );
- }
-